package com.xmkj.bearuser.pk;

import android.view.View;
import android.widget.EditText;

import com.common.cons.Constans;
import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.retrofit.bearusermethod.JuadeActiveMethods;
import com.common.retrofit.bearusermethod.JuadeRecommedMethods;
import com.common.retrofit.subscriber.CommonSubscriber;
import com.common.retrofit.subscriber.SubscriberListener;
import com.common.rxbus.RxBus;
import com.common.rxbus.postevent.RxKeyEvent;
import com.common.utils.EmptyUtils;
import com.common.utils.SPUtils;
import com.common.widget.navigation.WidgetButton;
import com.xmkj.bearuser.R;

/**
 * Create by leo
 * 创建日期：2018/6/27
 * 描述：
 */

public class JudgeActivity extends BaseMvpActivity {
    public static final String ACTIVITYID = "activityid";
    public static final String TYPE = "type";
    private String actvityid;
    private EditText etContent;
    private String type;

    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_judge;
    }

    @Override
    protected void onViewCreated() {
        etContent = findViewById(R.id.et_content);
        actvityid = getIntent().getStringExtra(ACTIVITYID);
        type = getIntent().getStringExtra(TYPE);
        setRightNavigationText();
    }

    private void setRightNavigationText() {
        m_navigationBar.setVisibility(View.VISIBLE);
        WidgetButton widgetButton = new WidgetButton(this, R.string.submit);
        widgetButton.getTextView().setTextColor(getResources().getColor(R.color.main_color));
        widgetButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
          /*    if(EmptyUtils.isEmpty(getEditTextStr(mEtName))||EmptyUtils.isEmpty(person_sex)||EmptyUtils.isEmpty(birth)){
                    showToastMsg("请填写完整信息");
                    return;
                }*/
//                gotoUpdateUser();
                if (EmptyUtils.isEmpty(getEditTextStr(etContent))) {
                    showToastMsg("请输入评价内容");
                    return;
                }
                if ("1".equals(type)) {
                    gotoHttpJuade();
                } else {
                    gotoRecommendHttpJuade();
                }
            }
        });
        m_navigationBar.setRightMenu(widgetButton);
    }

    private void gotoRecommendHttpJuade() {
        showProgressingDialog();
        CommonSubscriber<Object> subscriber = new CommonSubscriber<>(new SubscriberListener() {
            @Override
            public void onNext(Object o) {
                dismissProgressDialog();
                RxBus.getDefault().postSticky(new RxKeyEvent(RxKeyEvent.JUADEACTIVE_SUCCESS, true));
                showToastMsg("评价成功");
                onBackPressed();

            }

            @Override
            public void onError(String e, int code) {
                dismissProgressDialog();
                showToastMsg(e);
            }
        });


        JuadeRecommedMethods.getInstance().recommendComment(subscriber, SPUtils.getShareInt(Constans.UID), SPUtils.getShareString(Constans.HASHID), actvityid, getEditTextStr(etContent));
        rxManager.add(subscriber);
    }

    private void gotoHttpJuade() {
        showProgressingDialog();
        CommonSubscriber<Object> subscriber = new CommonSubscriber<>(new SubscriberListener() {
            @Override
            public void onNext(Object o) {
                dismissProgressDialog();
                RxBus.getDefault().postSticky(new RxKeyEvent(RxKeyEvent.JUADEACTIVE_SUCCESS, true));
                showToastMsg("评价成功");
                onBackPressed();

            }

            @Override
            public void onError(String e, int code) {
                dismissProgressDialog();
                showToastMsg(e);
            }
        });


        JuadeActiveMethods.getInstance().addComment(subscriber, SPUtils.getShareInt(Constans.UID), SPUtils.getShareString(Constans.HASHID), actvityid, getEditTextStr(etContent));
        rxManager.add(subscriber);

    }

    @Override
    protected void doLogicFunc() {

    }

    @Override
    protected void setNavigation() {
        setNavigationBack("我的评价");
    }
}
